/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.yurendao.OSFileSystem.myList;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import javax.swing.tree.TreePath;
import com.yurendao.OSFileSystem.data.DataAttribute;


/**
 *
 * @author Administrator
 */
public class MyListCellRenderer implements ListCellRenderer{

    private JPanel jplCell = new JPanel();
    private JLabel jlblCell = new JLabel("");
    private String filetype = "";
    private TreePath treepath = null;
    private int myFATNumber = 0;
    private JTextField jtfCell = new JTextField("aaaaa");
    private Border lineBorder = BorderFactory.createLineBorder(Color.RED);
    private Border emptyBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2);
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        Object[] pair = (Object[])value;
        jlblCell.setOpaque(true);
        jlblCell.setIcon((ImageIcon)pair[0]);
        //jlblCell.setText(pair[1].toString());       
        filetype = pair[1].toString();
        jtfCell.setText(pair[2].toString());
        jtfCell.setEditable(true);
        jtfCell.setFont(Font.getFont("楷体"));        
        treepath = (TreePath)pair[3];
        myFATNumber = Integer.parseInt(pair[4].toString());
        if(isSelected){
            jlblCell.setForeground(list.getSelectionForeground());
            jlblCell.setBackground(list.getSelectionBackground());
        }else{
            jlblCell.setForeground(list.getForeground());
            jlblCell.setBackground(list.getBackground());
        }
        jlblCell.setBorder(cellHasFocus? lineBorder:emptyBorder);
        jplCell.setLayout(new BorderLayout(2,1));
        jplCell.add(jlblCell,BorderLayout.CENTER);
        jplCell.add(jtfCell,BorderLayout.SOUTH);

        //设置 在JList中 显示的  每个Cell的 尺寸
        jplCell.setPreferredSize(new Dimension(DataAttribute.List_Icon_width,DataAttribute.List_Icon_height));
        //jlblCell.setPreferredSize(new Dimension(100,50));
        return jplCell;
    }

}
